FindControl
FindControl Find control selected in mouse-down event
#include <Controls.h> Control Manager
short FindControl( localPt, theWindow, whichCtl );
Point localPt ; a point in LOCAL coordinates
WindowPtr theWindow ; window containing localPt
ControlHandle * whichCtl ; receives handle of control; NIL=none
returns control part code; 0=none, 10=inButton, etc.
FindControl is used after a call to FindWindow to determine which control
(if any) has been clicked. It returns a handle to identify the control and a
control part code indicating which part of the control was selected.
localPt is a 4-byte Point structure, expressed in local ( window)
coordinates. It is normally the local equivalent of the where field of
an EventRecord obtained via WaitNextEvent.
theWindow identifies a window; the controlList of that window is searched for a
control which corresponds to localPt. This is normally a value
obtained from FindWindow.
whichCtl is the address of a 4-byte ControlHandle data type. Upon return, it
will contain a handle of the control located at localPt or NIL if no
active control exists at localPt.
Returns: a short; the part code identifying which part of the control was
selected. A return value of 0 indicates that localPt mouse press
occurred where no active control exists.
The following named constants identify part codes you might receive
for standard controls:
(0) None
inButton (10) Anywhere in a standard push button
inCheckBox (11) Anywhere in a check box or radio button
inUpButton (20) Up (or left) arrow in scroll bar
inDownButton (21) Down (or right) arrow in scroll bar
inPageUp (22) Above (or to the left of) thumb in scroll bar
inPageDown (23) Below (or to the right of) thumb in scroll bar
inThumb (129) Thumb of a scroll bar

Notes: FindControl is an important step in a normal event loop. It is called
when a mouse-down event occurs in the content region of an active window
owned by the application. Most often, this call is followed by a call to
TrackControl. A typical sequence includes:
WaitNextEvent Wait for something to happen (get theEvent)
if ( theEvent.what == mouseDown) ...
FindWindow See which window was pointed at:
if in myWindow and if inContent ...
GlobalToLocal Convert theEvent.where to local coordinates
FindControl See which control (if any) is there
if "instant" control (e.g., inPageUp), handle it
TrackControl ... else, let the user change his mind
... and perform the appropriate action
Note: Don't forget to convert the EventRecord.where point to local
coordinates!
If localPt is in an inactive or invisible control, or is not part of any
control at all, the return code is 0 and whichCtl is set to NIL. See